package com.peoit.honeycomb.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.peoit.honeycomb.dto.MessageContent;

import java.io.Serializable;

/**
 * 通用结果
 * Created by zhouqiu on 2014/11/4.
 */
public class CommonResultJsonDto implements Serializable {
    //返回消息
    private String msg;

    //返回要跳转的路径
    private String url;

    //返回状态
    private int status;

    //返回的数据
    @JsonProperty("result")
    private Object result;

    public CommonResultJsonDto( ) {
    }
    public CommonResultJsonDto(int status, String msg,String url, Object result) {
        this.status = status;
        this.msg = msg;
        this.result = result;
        this.url = url;
    }


    /**
     * 返回数据和消息
     * @param resultObj
     * @param message
     * @return
     */
    public static CommonResultJsonDto successOrFail(Object resultObj, String message) {
        return resultObj != null ? success(resultObj) : fail(message);
    }

    public static CommonResultJsonDto successOrFail(Object resultObj,String url, String message) {
        return resultObj != null ? success(url , message) : fail(url , message);
    }

    public static CommonResultJsonDto success() {
        return new CommonResultJsonDto(MessageContent.STATUS_OK, MessageContent.SUCCESS_MSG_TIP,null,null);
    }

    public static CommonResultJsonDto successHasUrl(String url) {
        return new CommonResultJsonDto(MessageContent.STATUS_OK,MessageContent.SUCCESS_MSG_TIP,url,null);
    }
    public static CommonResultJsonDto success(Object resultObj) {
        return new CommonResultJsonDto(MessageContent.STATUS_OK, MessageContent.SUCCESS_MSG_TIP, null ,resultObj);
    }

    public static CommonResultJsonDto success(String msg) {
        return new CommonResultJsonDto(MessageContent.STATUS_OK, msg,null,null);
    }

    public static CommonResultJsonDto success(String url,String msg) {
        return new CommonResultJsonDto(MessageContent.STATUS_OK, msg,url,null);
    }
    public static CommonResultJsonDto success(Object object,String msg) {
        return new CommonResultJsonDto(MessageContent.STATUS_OK, msg,null,object);
    }

    public static CommonResultJsonDto success(String url,String msg,Object object) {
        return new CommonResultJsonDto(MessageContent.STATUS_OK, msg,url,object);
    }

    public static CommonResultJsonDto fail() {
        return  new CommonResultJsonDto(MessageContent.STATUS_FAIL, MessageContent.FAIL_MSG_TIP,null,null);
    }
    public static CommonResultJsonDto failHasUrl(String url) {
        return  new CommonResultJsonDto(MessageContent.STATUS_FAIL, MessageContent.FAIL_MSG_TIP,url,null);
    }
    public static CommonResultJsonDto fail(String msg) {
        return  new CommonResultJsonDto(MessageContent.STATUS_FAIL, msg,null,null);
    }

    public static CommonResultJsonDto fail(String url,String msg) {
        return  new CommonResultJsonDto(MessageContent.STATUS_FAIL, msg,url,null);
    }
    public static CommonResultJsonDto fail(Object object,String msg) {
        return  new CommonResultJsonDto(MessageContent.STATUS_FAIL, msg,null,object);
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.result = result;
    }
}
